<template>
  <div class="pptist-editor">
    <EditorHeader class="layout-header" />
    <div class="layout-content">
      <Thumbnails class="layout-content-left" />
      <div class="layout-content-center">
        <TopTool class="center-top" />
        <Canvas class="center-body" :style="{ height: `calc(100% - ${remarkHeight + 40}px)` }" />
        <Remark class="center-bottom" v-model:height="remarkHeight" :style="{ height: `${remarkHeight}px` }" />
      </div>
      <CanvasTool class="tool_sty" @click="handleTool" />
      <Toolbar2
        v-if="toolActive === 'equipment' || toolActive === 'system'"
        class="layout-content-right"
        :toolActive="toolActive"
      />
      <Toolbar v-else class="layout-content-right" />
    </div>
  </div>
  <PptxHandler />
  <SelectPanel v-if="showSelectPanel" />
  <SearchPanel v-if="showSearchPanel" />
  <NotesPanel v-if="showNotesPanel" />

  <Modal :visible="!!dialogForExport" :width="680" @closed="closeExportDialog()">
    <ExportDialog />
  </Modal>
</template>

<script lang="ts" setup>
import { storeToRefs } from 'pinia'
import { useMainStore } from '@/store'
import useGlobalHotkey from '@/hooks/useGlobalHotkey'
import usePasteEvent from '@/hooks/usePasteEvent'

import EditorHeader from './EditorHeader/index.vue'
import Canvas from './Canvas/index.vue'
import CanvasTool from './CanvasTool/index.vue'
import TopTool from './CanvasTool/topTool.vue'
import Thumbnails from './Thumbnails/index.vue'
import Toolbar from './Toolbar/index.vue'
import Toolbar2 from './Toolbar/index_.vue'
import Remark from './Remark/index.vue'
import ExportDialog from './ExportDialog/index.vue'
import SelectPanel from './SelectPanel.vue'
import SearchPanel from './SearchPanel.vue'
import NotesPanel from './NotesPanel.vue'
import Modal from '@/components/Modal.vue'
import PptxHandler from './PptxParser.vue'
import { ref } from 'vue'

const mainStore = useMainStore()
const { dialogForExport, showSelectPanel, showSearchPanel, showNotesPanel } = storeToRefs(mainStore)
const closeExportDialog = () => mainStore.setDialogForExport('')

const remarkHeight = ref(40)
const toolActive = ref('')

const handleTool = (val) => {
  toolActive.value = val
}

useGlobalHotkey()
usePasteEvent()
</script>

<style lang="scss" scoped>
.tool_sty {
  height: fit-content;
  background-color: #fff;
  border-radius: 8px;
  margin-right: 10px;
  max-height: calc(100% - 30px);
  overflow-y: auto;
  width: 68px;
}
.pptist-editor {
  height: 100%;
  background-color: #f9f9f9;
}

.layout-header {
  height: 56px;
  margin-bottom: 10px;
}

.layout-content {
  height: calc(100% - 66px);
  display: flex;
}

.layout-content-left {
  flex-shrink: 0;
}

.layout-content-center {
  width: calc(100% - 160px - 60px - 260px);
  flex:1;

  .center-top {
    height: 40px;
  }
}

.layout-content-right {
  width: 260px;
  height: 100%;
}
</style>
